package com.base.action;

import java.util.List;

import com.base.service.CardTypeService;
import com.common.bean.Cardmaintype;
import com.common.bean.Cardsubtype;
import com.common.util.PagerModel;
import com.core.ssh2.AbstractActionSupport;

public class CardTypeAction extends AbstractActionSupport {
	private static final long serialVersionUID = 521348052306556414L;

	private CardTypeService cardTypeService;
	
	private Cardmaintype cardmaintype;
	
	private Cardsubtype cardsubtype;
	
	private long cardmaintypeno;
	
	private long cardsubtypeno;
	
	private List<Cardmaintype> maintypelist;
	
	private PagerModel pm;
	
	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
	
	public String findAllCardmaintype() throws Exception {
		pm = cardTypeService.findCardmaintypeForPager();
		return SUCCESS;
	}
	
	public String findCardmaintype() throws Exception {
		cardmaintype = cardTypeService.findCardmaintypeById(cardmaintypeno);
		pm = cardTypeService.findCardsubtypeForPager(cardmaintypeno);
		return SUCCESS;
	}
	
	public String goAddCardmaintype() throws Exception {
		return SUCCESS;
	}
	
	public String addCardmaintype() throws Exception {
		cardTypeService.addCardmaintype(cardmaintype);
		cardmaintypeno = cardmaintype.getCardmaintypeno();
		return SUCCESS;
	}
	
	public String deleteCardmaintype() throws Exception {
		cardTypeService.removeCardmaintype(cardmaintypeno);
		return SUCCESS;
	}
	
	public String goUpdateCardmaintype() throws Exception {
		cardmaintype = cardTypeService.findCardmaintypeById(cardmaintypeno);
		return SUCCESS;
	}
	
	public String updateCardmaintype() throws Exception {
		cardTypeService.updateCardmaintype(cardmaintype);
		cardmaintypeno = cardmaintype.getCardmaintypeno();
		return SUCCESS;
	}
	
	public String findCardsubtype() throws Exception {
		cardsubtype = cardTypeService.findCardsubtypeById(cardsubtypeno);
		return SUCCESS;
	}
	
	public String goAddCardsubtype() throws Exception {
		maintypelist = cardTypeService.findAllCardmaintype();
		return SUCCESS;
	}
	
	public String addCardsubtype() throws Exception {
		try{
			cardmaintype = cardTypeService.findCardmaintypeById(cardmaintypeno);
			if(cardmaintype == null) {
				throw new RuntimeException();
			}
		}catch(Exception ex) {
			throw new RuntimeException("has no maintype instance which cardmaintypeno is " + cardmaintypeno);
		}
		cardsubtype.setCardmaintype(cardmaintype);
		cardTypeService.addCardsubtype(cardsubtype);
		return SUCCESS;
	}
	
	public String deleteCardsubtype() throws Exception {
		cardTypeService.removeCardsubtype(cardsubtypeno);
		return SUCCESS;
	}
	
	public String goUpdateCardsubtype() throws Exception {
		cardsubtype = cardTypeService.findCardsubtypeById(cardsubtypeno);
		return SUCCESS;
	}
	
	public String updateCardsubtype() throws Exception {
		cardTypeService.updateCardsubtype(cardsubtype);
		cardmaintypeno = cardmaintype.getCardmaintypeno();
		return SUCCESS;
	}

	/**
	 * @return the cardmaintype
	 */
	public Cardmaintype getCardmaintype() {
		return cardmaintype;
	}

	/**
	 * @param cardmaintype the cardmaintype to set
	 */
	public void setCardmaintype(Cardmaintype cardmaintype) {
		this.cardmaintype = cardmaintype;
	}

	/**
	 * @return the cardmaintypeno
	 */
	public long getCardmaintypeno() {
		return cardmaintypeno;
	}

	/**
	 * @param cardmaintypeno the cardmaintypeno to set
	 */
	public void setCardmaintypeno(long cardmaintypeno) {
		this.cardmaintypeno = cardmaintypeno;
	}

	/**
	 * @return the cardsubtype
	 */
	public Cardsubtype getCardsubtype() {
		return cardsubtype;
	}

	/**
	 * @param cardsubtype the cardsubtype to set
	 */
	public void setCardsubtype(Cardsubtype cardsubtype) {
		this.cardsubtype = cardsubtype;
	}

	/**
	 * @return the cardTypeService
	 */
	public CardTypeService getCardTypeService() {
		return cardTypeService;
	}

	/**
	 * @param cardTypeService the cardTypeService to set
	 */
	public void setCardTypeService(CardTypeService cardTypeService) {
		this.cardTypeService = cardTypeService;
	}

	/**
	 * @return the pm
	 */
	public PagerModel getPm() {
		return pm;
	}

	/**
	 * @param pm the pm to set
	 */
	public void setPm(PagerModel pm) {
		this.pm = pm;
	}

	/**
	 * @return the cardsubtypeno
	 */
	public long getCardsubtypeno() {
		return cardsubtypeno;
	}

	/**
	 * @param cardsubtypeno the cardsubtypeno to set
	 */
	public void setCardsubtypeno(long cardsubtypeno) {
		this.cardsubtypeno = cardsubtypeno;
	}

	/**
	 * @return the maintypelist
	 */
	public List<Cardmaintype> getMaintypelist() {
		return maintypelist;
	}

	/**
	 * @param maintypelist the maintypelist to set
	 */
	public void setMaintypelist(List<Cardmaintype> maintypelist) {
		this.maintypelist = maintypelist;
	}
	
}
